home *** CD-ROM | disk | FTP | other *** search
/ CICA 1997 August / CICA - The Ultimate Collection of Shareware for Windows (Walnut Creek) (August 1997) (Disc 1).iso / utils / unix / unzip520 / wingui / iconbar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  15.5 KB  |  494 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <string.h>
  4. #include <commdlg.h>
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <time.h>
  8. #include "wingui\wizunzip.h"
  9.  
  10. #define DKGRAY_PEN      RGB(128, 128, 128)
  11. #define IB_SPACE        -1
  12.  
  13. typedef struct BUTTON_STRUCT
  14. {
  15. int    idBtn;
  16. LPCSTR ButtonHelp;
  17. LPCSTR hBMP;
  18. HWND   hWndBtn;
  19. } BUTTON, *LPBUTTON;
  20.  
  21. static WNDPROC pfnOldProc;
  22. static BOOL first = FALSE;
  23.  
  24. /* Forward declarations */
  25. void ButtonBar(HWND, LPBUTTON);
  26. void CreateButtonBar(HWND hWndParent);
  27. VOID SubClassButton (HWND hwnd, WNDPROC SubClassBtnProc);
  28. LRESULT CALLBACK SubClassBtnProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  29.  
  30. static HWND hHelpBtnWnd = NULL;
  31. HWND      hWndButtonBarOwner;
  32. HWND      hWndButtonBar;
  33. int       ButtonBarHeight;
  34. int       Width, Height;
  35. int BtnSeparator = 1;
  36. float BtnMult = (float)BTNWIDTH;
  37.  
  38. #define NumOfBtns 21
  39.  
  40. BUTTON    Buttons[NumOfBtns + 1];
  41. LPBUTTON  lpIB;
  42.  
  43. /*
  44.  *  function:  SubClassBtnProc
  45.  *
  46.  *  input parameters:  normal window procedure parameters.
  47.  *  global variables:
  48.  *   hWndButtonBar  - parent window of the control.
  49.  */
  50.  
  51. LRESULT CALLBACK SubClassBtnProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  52. {
  53. RECT rc, rw;
  54. POINT p;
  55.  
  56.   switch (message) {
  57.     case WM_MOUSEMOVE: {
  58.       int left;
  59.  
  60.       if (!uf.fShowBubbleHelp)
  61.          return 0;
  62.  
  63.       p.x = LOWORD(lParam); /* Get mouse coordinates */
  64.       p.y = HIWORD(lParam);
  65.  
  66.       for (lpIB = Buttons; lpIB->idBtn != 0; lpIB++)
  67.          {
  68.          if (lpIB->hWndBtn == hwnd)
  69.             {
  70.             if  (ChildWindowFromPoint(hwnd, p) != hwnd)
  71.                 {
  72.                 if (hHelpBtnWnd != NULL)
  73.                    DestroyWindow(hHelpBtnWnd);
  74.                 hHelpBtnWnd = NULL;
  75.                 if (GetCapture != NULL)
  76.                    ReleaseCapture();
  77.                 break; /* Mouse has moved off the button */
  78.                 }
  79.  
  80.             if (GetCapture() != hwnd)
  81.                {
  82.                SetCapture(hwnd);
  83.                /* Convert left, right corners of button to hWndMain
  84.                   coordinates
  85.                 */
  86.                WinAssert(hwnd);
  87.                GetClientRect(hwnd, &rc);
  88.                MapWindowPoints(hwnd, hWndMain, (POINT FAR *)&rc, 2);
  89.                WinAssert(hWndMain);
  90.                GetClientRect(hWndMain, &rw);
  91.  
  92.                if ((rc.left + ((lstrlen(lpIB->ButtonHelp)+1) * dxChar)) < rw.right)
  93.                   left = rc.left;
  94.                else
  95.                   left = rc.right - ((lstrlen(lpIB->ButtonHelp)+1) * dxChar);
  96.                hHelpBtnWnd = CreateWindow("EDIT", NULL,
  97.                   WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | ES_READONLY|WS_BORDER,
  98.                   left, rc.bottom,
  99.                   (lstrlen(lpIB->ButtonHelp)+1) * dxChar, (int)(1.4 * dyChar),
  100.                   hWndButtonBarOwner,
  101.                   (HMENU) NULL,
  102.                   (HANDLE) hInst,
  103.                   NULL);
  104.                SendMessage(hHelpBtnWnd, WM_SETFONT, (WPARAM)hFixedFont, FALSE);
  105.                SendMessage(hHelpBtnWnd, WM_SETTEXT, 0, (LPARAM)lpIB->ButtonHelp);
  106.                break;
  107.               }
  108.             }
  109.          }
  110.       return 0;
  111.       }
  112.     /*
  113.      * For messages that are not handled explicitly, pass them on
  114.      * to the original window procedure.
  115.      */
  116.     default:
  117.       if (hHelpBtnWnd != NULL)
  118.          {
  119.          DestroyWindow(hHelpBtnWnd);
  120.          hHelpBtnWnd = NULL;
  121.          if (GetCapture() != NULL)
  122.             ReleaseCapture();
  123.          }
  124.       return (CallWindowProc ((pfnOldProc), hwnd, message, wParam, lParam));
  125.     } /* end switch */
  126.  
  127. }
  128.  
  129. /*
  130.  *  function:  SubClassButton
  131.  *
  132.  *  input parameters:
  133.  *     hwnd            - window handle to be subclassed,
  134.  *     SubClassBtnProc - the new window procedure.
  135.  *
  136.  *  Set in a new window procedure for this window.  Store the old window
  137.  *  procedure in the first field of the extrabytes structure.  This routine
  138.  *  is specific to this program in the use of this particular extrabyte
  139.  *  structure.  Note that the pointer to the user bytes needs to be freed
  140.  *  later (in WM_DESTROY).
  141.  */
  142.  
  143. VOID SubClassButton (HWND hwnd, WNDPROC SubClassBtnProc)
  144. {
  145. WinAssert(hwnd);
  146. if (!first)
  147.    {
  148.    pfnOldProc = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);
  149.    first = TRUE;
  150.    }
  151. SetWindowLong (hwnd, GWL_WNDPROC,  (LONG) SubClassBtnProc);
  152. }
  153.  
  154. /* WARNING If you add a button, you must change the #define above for
  155.    NumOfBtns. Any more buttons, and you might have trouble with VGA, or
  156.    640x480 display modes.
  157. */
  158. void CreateButtonBar(HWND hWndParent)
  159. {
  160. int i=0;
  161.  
  162. Buttons[i].idBtn     = IDM_OPEN;
  163. Buttons[i].ButtonHelp = "Open Archive";
  164. Buttons[i++].hBMP = "OPEN_BUTTON";
  165.  
  166. Buttons[i].idBtn     = IDM_EXTRACT;
  167. Buttons[i].ButtonHelp = "Extract File(s) From Archive";
  168. Buttons[i++].hBMP = "EXTRACT_BUTTON";
  169.  
  170. Buttons[i].idBtn     = IDM_DISPLAY;
  171. Buttons[i].ButtonHelp = "Display File From Archive";
  172. Buttons[i++].hBMP = "DISPLAY_BUTTON";
  173.  
  174. Buttons[i].idBtn     = IDM_TEST;
  175. Buttons[i].ButtonHelp = "Test Archive";
  176. Buttons[i++].hBMP = "TEST_BUTTON";
  177.  
  178. Buttons[i].idBtn     = IDM_SHOW_COMMENT;
  179. Buttons[i].ButtonHelp = "Show Comment";
  180. Buttons[i++].hBMP = "COMMENT_BUTTON";
  181.  
  182. Buttons[i].idBtn     = IDM_COPY_ARCHIVE;
  183. Buttons[i].ButtonHelp = "Copy Archive";
  184. Buttons[i++].hBMP = "COPY_BUTTON";
  185.  
  186. Buttons[i].idBtn     = IDM_MOVE_ARCHIVE;
  187. Buttons[i].ButtonHelp = "Move Archive";
  188. Buttons[i++].hBMP = "MOVE_BUTTON";
  189.  
  190. Buttons[i].idBtn     = IDM_RENAME_ARCHIVE;
  191. Buttons[i].ButtonHelp = "Rename Archive";
  192. Buttons[i++].hBMP = "RENAME_BUTTON";
  193.  
  194. Buttons[i].idBtn     = IDM_DELETE_ARCHIVE;
  195. Buttons[i].ButtonHelp = "Delete Archive";
  196. Buttons[i++].hBMP = "DELETE_BUTTON";
  197.  
  198. Buttons[i].idBtn     = IDM_MAKE_DIR;
  199. Buttons[i].ButtonHelp = "Make Directory";
  200. Buttons[i++].hBMP = "MAKEDIR_BUTTON";
  201.  
  202. Buttons[i].idBtn     = IDM_SELECT_ALL;
  203. Buttons[i].ButtonHelp = "Select All Files";
  204. Buttons[i++].hBMP = "SELECTALL_BUTTON";
  205.  
  206. Buttons[i].idBtn     = IDM_DESELECT_ALL;
  207. Buttons[i].ButtonHelp = "De-Select All Files";
  208. Buttons[i++].hBMP = "DESELECTALL_BUTTON";
  209.  
  210. Buttons[i].idBtn     = IDM_SELECT_BY_PATTERN;
  211. Buttons[i].ButtonHelp = "Select Files By Pattern";
  212. Buttons[i++].hBMP = "SELECTPATTERN_BUTTON";
  213.  
  214. Buttons[i].idBtn     = IDM_CLEAR_STATUS;
  215. Buttons[i].ButtonHelp = "Clear Status/Display Window";
  216. Buttons[i++].hBMP = "CLEARSTATUS_BUTTON";
  217.  
  218. Buttons[i].idBtn     = IDM_COPY;
  219. Buttons[i].ButtonHelp = "Copy Status/Display Window To Clipboard";
  220. Buttons[i++].hBMP = "COPYSTATUS_BUTTON";
  221.  
  222. Buttons[i].idBtn     = IDM_CHDIR;
  223. Buttons[i].ButtonHelp = "Unzip To Directory";
  224. Buttons[i++].hBMP = "UNZIPTODIR_BUTTON";
  225.  
  226. Buttons[i].idBtn     = IDM_MAX_LISTBOX;
  227. Buttons[i].ButtonHelp = "Maximize Archive Listbox";
  228. Buttons[i++].hBMP = "LIST_BUTTON";
  229.  
  230. Buttons[i].idBtn     = IDM_SPLIT;
  231. Buttons[i].ButtonHelp = "Split Display Windows";
  232. Buttons[i++].hBMP = "SPLIT_BUTTON";
  233.  
  234. Buttons[i].idBtn     = IDM_MAX_STATUS;
  235. Buttons[i].ButtonHelp = "Maximize Status/Display Window";
  236. Buttons[i++].hBMP = "STATUS_BUTTON";
  237.  
  238. Buttons[i].idBtn     = IDM_EXIT;
  239. Buttons[i].ButtonHelp = "Exit WizUnZip";
  240. Buttons[i++].hBMP = "EXIT_BUTTON";
  241.  
  242. Buttons[i].idBtn     = IDM_HELP;
  243. Buttons[i].ButtonHelp = "WizUnZip Help";
  244. Buttons[i++].hBMP = "HELP_BUTTON";
  245.  
  246. Buttons[i].idBtn     = 0;
  247. Buttons[i].ButtonHelp = NULL;
  248. Buttons[i].hWndBtn   = NULL;
  249.  
  250. ButtonBar(hWndParent, Buttons);
  251. return;
  252. }
  253.  
  254. void ButtonBar(HWND hWndParent, LPBUTTON lpButton)
  255. {
  256. int          i, x;
  257. RECT         rect;
  258.  
  259. hWndButtonBarOwner  = hWndParent;
  260. Height    = (int)(1.75*dyChar);
  261. ButtonBarHeight = 2 + Height;
  262. WinAssert(hWndParent);
  263. GetClientRect(hWndParent, &rect);
  264. hWndButtonBar = CreateWindow("ButtonBar", NULL,
  265.         WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_BORDER,
  266.         0, 0, rect.right - rect.left, ButtonBarHeight,
  267.         hWndButtonBarOwner, (HMENU) NULL, (HINSTANCE) hInst, NULL);
  268. SetWindowPos(hWndButtonBar, (HWND) 1, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
  269. WinAssert(hWndButtonBar);
  270. ShowWindow(hWndButtonBar, SW_SHOW);
  271. BtnMult = (float)BTNWIDTH; /* Reset multiplier to original setting */
  272. BtnSeparator = 1;   /* Set distance between buttons back to 1 */
  273. Width = (int)(BtnMult*dxChar);
  274.  
  275. WinAssert(hWndParent);
  276. GetClientRect(hWndParent, &rect);
  277. if (((Width * NumOfBtns) + NumOfBtns) > rect.right)
  278.    {
  279.    while (BtnMult > MIN_BTN_WIDTH)
  280.       {
  281.       BtnMult = (float)(BtnMult - 0.1);
  282.       Width = (int)(BtnMult*dxChar);
  283.       if (((Width * NumOfBtns) + NumOfBtns) < rect.right)
  284.          continue;
  285.       }
  286.    }
  287.  
  288. /* Last ditch effor to get all the buttons on the screen */
  289. if (((Width * NumOfBtns) + NumOfBtns) > rect.right)
  290.    {
  291.    BtnSeparator = 0;
  292.    }
  293.  
  294. x = BtnSeparator;
  295.  
  296. for (lpIB = lpButton; lpIB->idBtn != 0; lpIB++)
  297.     {
  298.     if (lpIB->idBtn == -1)
  299.        continue;
  300.     (lpIB->hWndBtn) = CreateWindow("BUTTON", "",
  301.                       WS_VISIBLE | BS_OWNERDRAW | WS_CHILD,
  302.                       x, 0,
  303.                       Width, Height,
  304.                       hWndButtonBar,
  305.                       (HMENU) lpIB->idBtn, (HINSTANCE) hInst, NULL );
  306.     SubClassButton (lpIB->hWndBtn, SubClassBtnProc);
  307.     x += Width + BtnSeparator;
  308.     }
  309. i = 0;
  310. hOpen          = Buttons[i++].hWndBtn ;
  311. hExtract       = Buttons[i++].hWndBtn ;
  312. hDisplay       = Buttons[i++].hWndBtn ;
  313. hTest          = Buttons[i++].hWndBtn ;
  314. hShowComment   = Buttons[i++].hWndBtn ;
  315. hCopyArchive   = Buttons[i++].hWndBtn ;
  316. hMoveArchive   = Buttons[i++].hWndBtn ;
  317. hRenameArchive = Buttons[i++].hWndBtn ;
  318. hDeleteArchive = Buttons[i++].hWndBtn ;
  319. hMakeDir       = Buttons[i++].hWndBtn ;
  320. hSelectAll     = Buttons[i++].hWndBtn ;
  321. hDeselectAll   = Buttons[i++].hWndBtn ;
  322. hSelectPattern = Buttons[i++].hWndBtn ;
  323. hClearStatus   = Buttons[i++].hWndBtn ;
  324. hCopyStatus    = Buttons[i++].hWndBtn ;
  325. hUnzipToDir    = Buttons[i++].hWndBtn ;
  326. hListBoxButton = Buttons[i++].hWndBtn ;
  327. hSplitButton   = Buttons[i++].hWndBtn ;
  328. hStatusButton  = Buttons[i++].hWndBtn ;
  329. hExit          = Buttons[i++].hWndBtn ;
  330. hHelp          = Buttons[i].hWndBtn ;
  331.  
  332. EnableWindow(hCopyStatus, FALSE);
  333.  
  334. return;
  335. }
  336.  
  337. void MoveButtons(void)
  338. {
  339. int x = BtnSeparator;
  340.  
  341. for (lpIB = Buttons; lpIB->idBtn != 0; lpIB++)
  342.     {
  343.     WinAssert(lpIB->hWndBtn);
  344.     MoveWindow(lpIB->hWndBtn, x, 0, Width, Height, TRUE);
  345.     x += Width + BtnSeparator;
  346.     }
  347. }
  348.  
  349. LRESULT WINAPI ButtonBarWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  350. {
  351. HPEN             hPen, hOldPen;
  352. HBRUSH           hBrush;
  353. RECT             rect;
  354. PAINTSTRUCT      ps;
  355. LPDRAWITEMSTRUCT lpdis;
  356. HDC              hdcMem;
  357. HBITMAP          hBitmap;
  358. long             flag;
  359. int              i;
  360.  
  361. switch(message)
  362.    {
  363.    case WM_COMMAND:
  364.         SendMessage(hWndButtonBarOwner, message, wParam, lParam);
  365.         return(FALSE);
  366.  
  367.    case WM_DRAWITEM:
  368.         lpdis = (LPDRAWITEMSTRUCT) lParam;
  369.         lpIB = Buttons;
  370.         for (i=0;;i++)
  371.            {
  372.            if (lpIB[i].idBtn == 0)
  373.                return (FALSE); /* Not one of our controls */
  374.            if (lpIB[i].idBtn == (signed int)lpdis->CtlID)
  375.                break;          /* Found the right control */
  376.            }
  377.         lpdis->rcItem.right = Width;
  378.         lpdis->rcItem.bottom = Height;
  379.  
  380.         lpdis->rcItem.right--;
  381.         lpdis->rcItem.bottom--;
  382.  
  383.         hBrush = CreateSolidBrush(RGB(192, 192, 192));
  384.         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
  385.         DeleteObject(hBrush);
  386.         hOldPen = SelectObject(lpdis->hDC, GetStockObject(BLACK_PEN));
  387.         MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top, NULL);
  388.         LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);
  389.         LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.bottom);
  390.         LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom);
  391.         LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);
  392.         SelectObject(lpdis->hDC, hOldPen);
  393.         lpdis->rcItem.left++;
  394.         lpdis->rcItem.right--;
  395.         lpdis->rcItem.top++;
  396.         lpdis->rcItem.bottom--;
  397.         if (!IsWindowEnabled(lpIB[i].hWndBtn))
  398.            {
  399.            flag = SRCINVERT;  /* "Gray" out button */
  400.            }
  401.         else
  402.            {
  403.            flag = SRCCOPY;
  404.            }
  405.         if (lpdis->itemState & ODS_SELECTED)
  406.            {
  407.            /* Button has been depressed - make it look depressed */
  408.            hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);
  409.            hOldPen = SelectObject(lpdis->hDC, hPen);
  410.            MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);
  411.            LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);
  412.            LineTo(lpdis->hDC, lpdis->rcItem.right, lpdis->rcItem.top);
  413.            SelectObject(lpdis->hDC, hOldPen);
  414.            DeleteObject(hPen);
  415.            hdcMem = CreateCompatibleDC(lpdis->hDC);
  416.            hBitmap = LoadBitmap(hInst, lpIB[i].hBMP);
  417.            hOldPen = SelectObject(hdcMem, hBitmap);
  418.            StretchBlt(lpdis->hDC,   /* device to be drawn */
  419.               lpdis->rcItem.left+2, /* x upper left destination */
  420.               lpdis->rcItem.top+2,  /* y upper left destination */
  421.               lpdis->rcItem.right - lpdis->rcItem.left -2, /* width */
  422.               lpdis->rcItem.bottom - lpdis->rcItem.top - 2,/* height */
  423.               hdcMem, /* source bitmap */
  424.               0,      /* x upper left source */
  425.               0,      /* y upper left source */
  426.               32,     /* source bitmap width */
  427.               32,     /* source bitmap height */
  428.               flag);
  429.            SelectObject(hdcMem, hOldPen);
  430.            DeleteDC(hdcMem);
  431.            DeleteObject(hBitmap);
  432.            }
  433.         else
  434.            {
  435.            /* Draw button */
  436.            hOldPen = SelectObject(lpdis->hDC, GetStockObject(WHITE_PEN));
  437.            MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);
  438.            LineTo(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top);
  439.            LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);
  440.            SelectObject(lpdis->hDC, hOldPen);
  441.            hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);
  442.            hOldPen = SelectObject(lpdis->hDC, hPen);
  443.            MoveToEx(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.bottom,NULL);
  444.            LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.bottom);
  445.            LineTo(lpdis->hDC,lpdis->rcItem.right,lpdis->rcItem.top);
  446.            SelectObject(lpdis->hDC, hOldPen);
  447.            DeleteObject(hPen);
  448.            hdcMem = CreateCompatibleDC(lpdis->hDC);
  449.            hBitmap = LoadBitmap(hInst, lpIB[i].hBMP);
  450.            hOldPen = SelectObject(hdcMem, hBitmap);
  451.            StretchBlt(lpdis->hDC,
  452.               lpdis->rcItem.left+2,
  453.               lpdis->rcItem.top+2,
  454.               lpdis->rcItem.right - lpdis->rcItem.left -2,
  455.               lpdis->rcItem.bottom - lpdis->rcItem.top - 2,
  456.               hdcMem,
  457.               0,
  458.               0,
  459.               32,
  460.               32,
  461.               flag); /* This flag makes it look either enabled or greyed */
  462.            SelectObject(hdcMem, hOldPen);
  463.            DeleteDC(hdcMem);
  464.            DeleteObject(hBitmap);
  465.            }
  466.         return TRUE;
  467.    case WM_PAINT:
  468.         BeginPaint(hWnd, &ps);
  469.         WinAssert(hWnd);
  470.         GetClientRect(hWnd, &rect);
  471.         hOldPen = SelectObject(ps.hdc, GetStockObject(WHITE_PEN));
  472.         MoveToEx(ps.hdc, rect.left, rect.top, NULL);
  473.         LineTo(ps.hdc, rect.right+1, rect.top);
  474.         SelectObject(ps.hdc, hOldPen);
  475.         hPen = CreatePen(PS_SOLID, 1, DKGRAY_PEN);
  476.         hOldPen = SelectObject(ps.hdc, hPen);
  477.         MoveToEx(ps.hdc, rect.left, rect.bottom-2, NULL);
  478.         LineTo(ps.hdc, rect.right+1, rect.bottom-2);
  479.         SelectObject(ps.hdc, hOldPen);
  480.         DeleteObject(hPen);
  481.         hPen = CreatePen( PS_SOLID, 1, BLACK_PEN);
  482.         hOldPen = SelectObject(ps.hdc, hPen);
  483.         MoveToEx(ps.hdc, rect.left, rect.bottom-1, NULL);
  484.         LineTo(ps.hdc, rect.right+1, rect.bottom-1);
  485.         SelectObject(ps.hdc, hOldPen);
  486.         DeleteObject(hPen);
  487.         EndPaint(hWnd, &ps);
  488.         return (FALSE);
  489.    default:
  490.       return(DefWindowProc(hWnd, message, wParam, lParam));
  491.    }
  492. }
  493.  
  494.